package quake.dao;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.simpledb.AmazonSimpleDB;
import com.amazonaws.services.simpledb.AmazonSimpleDBClient;

public abstract class AbstractDao {
    protected static final String ATTRIBUTES_THE_USER = "theUser";
    protected static final String ATTRIBUTES_APPROX_TIME = "approxTime";
    protected static final String ATTRIBUTES_THE_TWEET = "theTweet";
    protected static final String ATTRIBUTES_HASHTAGS = "hashtags";

    private static final String PREFIX_DOMAIN = "Day";
    private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMdd");

    protected AmazonSimpleDB service;

    public AbstractDao(String accessKey, String secretKey) {
        service =
            new AmazonSimpleDBClient(new BasicAWSCredentials(accessKey, secretKey));
    }

    protected String nowDomain() {
        return PREFIX_DOMAIN + DATE_FORMAT.format(new Date());
    }

    protected String yesterdayDomain() {
        Calendar c = Calendar.getInstance();
        c.set(Calendar.DAY_OF_MONTH, c.get(Calendar.DAY_OF_MONTH) - 1);

        return PREFIX_DOMAIN + DATE_FORMAT.format(c.getTime());
    }
}
